package kr.or.mst.takeoutnote2;

import java.io.File;

import kr.or.mst.takeoutnote2.image.BitmapDownloaderTask;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ContentsAdapter extends ArrayAdapter<File> {
	
	private int res;

	public ContentsAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
		// TODO Auto-generated constructor stub
		this.res = textViewResourceId;
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;
		if(view==null)
			view = View.inflate(getContext(), this.res, null);
		
		ImageView iv_Picture = (ImageView) view.findViewById(R.id.ImageView_Picture);
		TextView tv_FileName = (TextView) view.findViewById(R.id.TextView_FileName);
		
		iv_Picture.setTag(this.getItem(position).getAbsolutePath());
		imgGetter(this.getItem(position).getAbsolutePath(), iv_Picture);
		tv_FileName.setText(this.getItem(position).getName());
		
		return view;
	}
	
	public void imgGetter(String url, ImageView imageView){
		BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
		task.execute(url);
	}
	
}
